




$(function(){


$('#login').on('click',function(){

var  account=    $('#account').val().trim()
var password=  $('#password').val().trim()

// if (loginInfo.account.length < 5) {
//     return callback('账号最短为 5 个字符');
// }
// if (loginInfo.password.length < 6) {
//     return callback('密码最短为 6 个字符');
// }


if(account.length<5) return  alert('账号最短为 5 个字符') 

if(password.length<5) return  alert('密码最短为 5 个字符') 


// {"username":"zhoushugang","password":"123456"}

var params={
    username:account,
    password:password
}

$.ajax({
    url:'/user/login',
    type:"post",
    data:params,
    success:function(res) {
        console.log(res);
        if(res.success) {
           
             setTimeout(function(){
                 localStorage.setItem('status',true)
                 window.location.href='user.html'
             },1000)

        }

    }

})



})



})



// login = function(loginInfo, callback) {
//     callback = callback || $.noop;
//     loginInfo = loginInfo || {};
//     loginInfo.account = loginInfo.account || '';
//     loginInfo.password = loginInfo.password || '';
//     if (loginInfo.account.length < 5) {
//         return callback('账号最短为 5 个字符');
//     }
//     if (loginInfo.password.length < 6) {
//         return callback('密码最短为 6 个字符');
//     }
//     var users = JSON.parse(localStorage.getItem('$users') || '[]');
//     var authed = users.some(function(user) {
//         return loginInfo.account == user.account && loginInfo.password == user.password;
//     });
//     if (authed) {
//         return owner.createState(loginInfo.account, callback);
//     } else {
//         return callback('用户名或密码错误');
//     }
// };